import ServerCenter from "../../Server/ServerCenter";
import QuestSpawn from "../QuestSpawn";
import SoundUtil from "../../Fantasy/Util/SoundUtil";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SelectButtonJs extends cc.Component {

    isTure = false;
    gameJs;
    questExp
    setIsTure(nodeJs,bool,num){
        this.gameJs = nodeJs;
        this.questExp = num;
        this.isTure = bool;

    }
    onDisable(){

    }
    clickButton(){
        if(this.isTure == true){
            SoundUtil.playEffect("music/correct");
            var self = this;
            Log("恭喜你答对了");
            this.gameJs.updateExp(this.questExp);
            if(QuestSpawn.isContest == true){
                self.gameJs.initQuest();
            }else if(QuestSpawn.isWrong == true){
                this.node.getChildByName("true").active = true;
                this.node.getComponent(cc.Button).enabled = false;
            }
            else{
                this.node.getChildByName("true").active = true;
                setTimeout(()=>{
                    if(this.node){
                        self.gameJs.initQuest();
                    }
                },300)
            }
        }else{
            var self = this;
            SoundUtil.playEffect("music/wrong");
            Log("很遗憾，你答错了");
            if(QuestSpawn.isContest == true){
                this.gameJs.updateExp(this.questExp,false);
                setTimeout(()=>{
                    self.gameJs.initQuest();
                },500)
            }else if(QuestSpawn.isWrong == true){
                this.node.getComponent(cc.Button).enabled = false;
            }else{
                if(this.gameJs.updateLife){
                    this.gameJs.updateLife();
                }
                this.node.getChildByName("false").active = true;
                setTimeout(()=>{
                    if(this.node){
                        self.node.getChildByName("false").active = false;
                    }
                },300)

            }
        }

    }
    
}
